//
//  ZFToolViewController.swift
//  map
//
//  Created by fyzq on 2024/1/24.
//

import UIKit
import SnapKit
import FloatingPanel
import MapboxMaps
class ZFMenuViewController: ZFBaseViewController {
    weak var mapManager:ZFMapManager!
    var toolScrollView:ZFMenuScrollView!
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = .clear
        setUI()
    }
  
    fileprivate func setUI(){
        
        toolScrollView = ZFMenuScrollView(frame: CGRectZero)
        view.addSubview(toolScrollView)
        toolScrollView.snp.makeConstraints { make in
            make.top.equalTo(20)
            make.left.right.bottom.equalToSuperview()
        }
        
        onMenuAction()
        
        
    }

    
  

}

extension ZFMenuViewController {
    
    fileprivate func onMenuAction(){
        toolScrollView.menuView.subject.subscribe(onNext: {[weak self]modal in
            guard let self = self else {return}
            switch modal.title {
            case "工具":
                let vc = ZFSettingViewController()
                self.navigationController?.pushViewController(vc, animated: true)
                break
            case "行政区域":
//                view.jk.currentVC
//                view.jk.findSubview(type: <#T##UIResponder.Type#>, resursion: <#T##Bool#>)
//                guard let cl =  view.jk_findSuperView(withSuperViewClass: SurfaceView.self) as? SurfaceView,
//                        let fpc = cl.jk_viewController as? FloatingPanelController else {
//                    return
//                }
//                self.mapManager.fly(options: CameraOptions(zoom: 2))
//                fpc.move(to: .tip, animated: true)
//                let regionView = ZFRegionView()
//                regionView.subject.subscribe(onNext: {[weak self] featureCollection in
//                    guard let self = self,
//                          let feature = featureCollection.features.first,
//                          let properties = feature.properties else {return}
//                    
//                    let level = properties.rawValue["level"] as! String
//                    let center = properties.rawValue["center"] as! [Double]
//                    var zoom :CGFloat = 2;
//                    if level == "province" {
//                        zoom = 4
//                    }else if level == "city" {
//                        zoom = 8
//                    }else {
//                        zoom = 11
//                    }
//                    self.mapManager.fly(options: CameraOptions(center: CLLocationCoordinate2D(latitude: center.last!, longitude: center.first!), zoom: zoom))
//                    self.mapManager.updateRegionSource(jsonSource: featureCollection)
//                },onDisposed: { [weak self] in
//                    guard let self = self else {return}
//                    self.mapManager.updateRegionSource(jsonSource: FeatureCollection(features: []))
//                }).disposed(by: regionView.dis)
//                ZFSwiftMessage.show(view: regionView,presentationStyle: .top,dimMode: .none,presentationContext: .viewController(fpc))

                break
            default: break
                
            }
            
        
            
        }).disposed(by: dis)
    }
    
    
}


extension ZFMenuViewController {
    
//    fileprivate func regionAction(code:String){
//       
//        ZFNetRequest.geojson(code: code).subscribe(onNext: {[weak self]data in
//            guard let self = self else {return}
//            do {
//                let  featureCollection = try JSONDecoder().decode(FeatureCollection.self, from: data)
//                 print(featureCollection)
//                
//                self.mapManager.updateRegionSource(jsonSource: featureCollection)
//            } catch {
//                print("Error parsing data: \(error)")
//            }
//        }).disposed(by: dis)
//    }
    

    
}
